﻿using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using MikeKappel.Com.CS.Model;

namespace MikeKappel.Com.CS.Services
{
    // NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config and in the associated .svc file.
    public class DateDifferentialService : IDateDifferentialService
    {
        /// <summary>
        /// DateDifferential is for returning the difference 
        /// between two dates in the year, month, and day format
        /// </summary>
        /// <param name="firstDate">First Date</param>
        /// <param name="secondDate">Secound Date</param>
        /// <returns>Diffrence as DateDifferential</returns>
        [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetDateDifferential/{firstDate}/{secondDate}")]
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetDateDifferential", Method = "PUT")]
        public DateDifferentialServiceType GetDateDifferential(DateTime firstDate, DateTime secondDate)
        {
            var differential = new DateDifferential(firstDate, secondDate, true, true, true, true, true, true, true, DateDifferential.DetailType.Milliseconds);
            return new DateDifferentialServiceType(differential);
        }

        /// <summary>
        /// DateDifferential is for returning the difference 
        /// between two dates in the year, month, and day format
        /// </summary>
        /// <param name="firstDate">First Date</param>
        /// <param name="secondDate">Secound Date</param>
        /// <returns>Diffrence as DateDifferential</returns>
        [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetDateDifferentialString/{firstDate}/{secondDate}")]
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetDateDifferentialString", Method = "PUT")]
        public String GetDateDifferentialString(DateTime firstDate, DateTime secondDate)
        {
            return GetDateDifferential(firstDate, secondDate).ToString();
        }
    }
}